package shape2D;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;

// 重叠图形的操作(形成新的图形)
public class OverlappedShape extends Application {
	private Pane root = new Pane();
	private Shape s1;
	private Shape s2;
	private Shape s3;
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {
		
		Circle circle1 = new Circle(100, 100, 50);
		Rectangle rectangle1 = new Rectangle(50, 50, 100, 100);
		s1 = Shape.intersect(circle1, rectangle1);		// 取相交部分
		
		Circle circle2 = new Circle(300, 100, 50);
		Rectangle rectangle2 = new Rectangle(300, 100, 100, 100);	// 图形结合
		s2 = Shape.union(circle2, rectangle2);
		
		Circle circle3 = new Circle(500, 100, 50);
		Rectangle rectangle3 = new Rectangle(500, 100, 100, 100);	// 前面图形减去重合部分
		s3 = Shape.subtract(circle3, rectangle3);
		root.getChildren().addAll(s1, s2, s3);
		
		Scene scene = new Scene(root, 600, 400);
		stage.setScene(scene);
		stage.show();
	}
}
